package cn.bs.seckill.config;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.Queue;
import org.springframework.amqp.core.TopicExchange;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class RabbitConfig {

    private static final String QUEUE = "seckillQueue";
    private static final String EXCHANGE = "seckillExchange";
    private static final String ROUTING_KEY1 = "seckill.*";


    //新建队列一
    @Bean
    public Queue queue() {
        return new Queue(QUEUE);
    }
    //新建主题模式交换机
    @Bean
    public TopicExchange topicExchanges() {
        return new TopicExchange(EXCHANGE);
    }
    //把队列和交换机以及路由键绑定
    @Bean
    public Binding binding() {
        return BindingBuilder.bind(queue()).to(topicExchanges()).with(ROUTING_KEY1);
    }
}
